// pages/programs/detail/detail.js
let {
  addDingLog,
  addOperateLog,
  updatePrograms,
  addFastPrograms,
} = require("../../../api/programs/add");
let {
  getProjectFollow,
  getFollow,
  addProgress,
  getProgress,
  timeOuts,
  theonefollow,
  hgjfilesfollow,
} = require("../../../api/programs/follow.js");
let {
  getProjectDetail,
  getEnterprise,
  getrequirement,
  getscience,
  getEnterpriselisInfo,
  pullProject,
  DDNotify,
  getRequire,
  torkAbandon,
  followAbandon,
  searchQy,
  searchDJ,
  contactsEnterprise,
  getGround,
  addRecover,
  getRecover,
  getRecoverList,
  contactsFws,
  getEnterpriseContacts,
} = require("../../../api/programs/Detail.js");
let {
  folllowRiever,
  applyEvaluation,
  getEvaluationMan,
  taskEvaluation,
  gettaskEvaluation,
  applytask,
  getevaluateList,
} = require("../../../api/programs/evaluate.js");
let {
  getProjectMember,
  addMember,
  getMemberList,
  insertNewProject,
  searchConnection,
} = require("../../../api/programs/follow.js");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    RecoverList: [],
    sffp: 0,
    fwsData: {},
    djList: [],
    fwsnameDj: "",
    searchDj: false,
    djShow: false,
    followedit: false,
    // 打卡
    DK: false,
    pgsm: "",
    xmsq: "",
    // 延期时间
    outXmz: "",
    outXmzShow: false,
    xmzbh: "",
    xmzname: "",
    // 联系人
    OrganizationPersen: {},
    OrganizationShow: false,
    // 复盘
    RecoverShow: false,
    RecoverData: {},
    RecoverNr: {},

    // 落地
    groundShow: false,
    groundData: {},
    // 快速提报新项目
    GocreatedShow: false,
    programType: ["载体项目", "产业项目", "科技项目", "人才项目", "政策项目"],
    systemInfo: null,
    createdShow: false,
    createdFormProject: false,
    pickerAddShow: false,
    systemInfo: {},
    // 判断是否走流转
    turnoverShowOne: false,
    turnoverShowTwo: false,
    // 判断政策项目是否流转
    policyShow: false,
    policyNum: "预计税收100万以下",
    contactsEnterpriseData: {
      bs: 0,
      khbh: "",
      xmbh: "",
      xmly: "",
      qymc: "",
      jgdmh: "",
    },

    QyList: [],
    xmsqShow: false,
    AbandonType: "",
    AbandonShow: false,
    AbandonContent: "",
    jind: {
      wc: 0,
      tg: 0,
    },
    showTaskInfo: false,
    progressList: [],
    progressShow: false,
    progressData: {},
    followList: {},
    formatter(type, value) {
      if (type === "year") {
        return `${value}年`;
      }
      if (type === "month") {
        return `${value}月`;
      }
      return value;
    },
    minDate: new Date().getTime(),
    gjsjShow: false,
    xcsjShow: false,

    khjdType: ["初步接触", "持续跟进", "强烈意向", "达成洽谈"],
    khjdShow: false,
    gjlxType: ["上门拜访", "来访接待", "线上拜访"],
    pickerShow: false,

    FollowShow: false,
    fieldNames: {
      text: "fwsrname",
      value: "fwsrname",
      children: "child",
    },
    showGjsj: false,
    showXcsj: false,
    showfwrname: false,
    projectFollow: {
      fwrname: "",
      zsph: "",
      selectedID: 1,
      gjlx: "上门拜访",
      khjd: "初次接触",
      gjsj: "",
      gjnr: "",
      xcsj: "",
      xmbh: "",
      khbh: "",
      rybh: "",
      bm: "",
      tname: "",
      xmzbh: "",
    },
    connectionList: [], // 组织机构加联系人
    activeName: "1",
    evaluateShow: false,
    evaluateRadio: 1,
    projectStatus: 1,
    projectMember: null,
    MemberShow: false,
    Mname: "",
    MemberList: [],
    MemberData: {
      xmbh: "",
      cyname: "",
      rybh: "",
      tname: "",
      tjsj: "",
    },
    enterpriseIsShow: false, //选择企业
    enterpriseShow: false,
    requirementShow: false,
    scienceShow: false,
    showTask: false,
    taskData: {
      a1: 1,
      a2: 1,
      a3: 1,
      a4: 1,
      a5: 1,
      pgf: 5,

      pgsm: "",
      sfwc: "",
      sftg: "2",
      xmbh: "",
      pgname: "",
    },
    taskInfo: {},
    radio: "2",
    xmbh: null,
    projectDetail: null,
    requirement: null,
    science: null,
    evaluation: null,
    yemc: null,
    enterpriseInputshow: false,
    sfrzqy: "0",
    enterpriseDetail: {
      sfrzqy: 0,
      xmbh: "", //项目编号
      qymc: "", //企业名称
      khbh: "", //企业编号
      zczb: "", //注册资本
      clsj: "", //成立时间
      zcdz: "", //注册地址
      qyfr: "", //法人代表
      hyfla: "", //一级行业分类
      hyflb: "", //二级行业分类
      lxr: "", //联系人
      lxphone: "", //手机号码
      lxphone2: "", //其他联系方式
      nys: "", //年营收(万元)
      nss: "", //年税收(万元)
      zyyw: "", //主营业务
      ygrs: "", //员工人数
      xcdlx: "", //现有场地类型
      xmj: "", //现有场地面积
      zycp: "", //主营产品
      qyzz: "", //资质
      zysc: "", //主要市场区域
      qysb: "", //社保情况
      khlx: "", //客户类型}
    },
  },
  // 点击大图

  clickImg: function (e) {
    let { url } = e.currentTarget.dataset;
    wx.previewImage({
      urls: [url], //需要预览的图片http链接列表，注意是数组
      current: "", // 当前显示图片的http链接，默认是第一个
      success: function (res) {},
      fail: function (res) {},
      complete: function (res) {},
    });
  },
  contactsFwsAdd() {
    contactsFws(this.data.fwsData).then((res) => {
      wx.showToast({
        title: "已成功关联对接方",
        icon: "none",
      });
      this.getProjectMember();
      this.opensearchDj();
      this.openDJ();
    });
  },
  onDJSearchChange(e) {
    this.setData({
      fwsnameDj: e.detail,
    });
  },
  onDJSearch() {
    if (this.data.fwsnameDj.length < 4) {
      wx.showToast({
        title: "关键词长度不得小于4字符",
        icon: "none",
      });
    } else {
      console.log(this.data.fwsnameDj);
      searchDJ(this.data.fwsnameDj).then((res) => {
        this.setData({
          djList: res.data,
        });
      });
    }
  },
  onDJSelect(e) {
    this.setData({
      fwsnameDj: e.detail,
    });
  },
  onClickDJItem(e) {
    let { jglb, fwlb, fwsname, fwsbh, jgdmh } = e.currentTarget.dataset;
    getEnterpriseContacts(fwsbh).then((res) => {
      if (res.data == 1) {
        wx.showToast({
          title: "当前企业处于流转阶段",
          icon: "none",
        });
      } else {
        this.setData({
          "fwsData.jglb": jglb,
          "fwsData.fwlb": fwlb,
          "fwsData.fwsname": fwsname,
          "fwsData.fwsbh": fwsbh,
          "fwsData.xmbh": this.data.projectDetail.xmbh,
          "fwsData.jgdmh": jgdmh,
          fwsnameDj: fwsname,
        });
      }
    });
  },

  opensearchDj() {
    this.setData({
      searchDj: !this.data.searchDj,
    });
    this.setData({
      fwsnameDj: "",
      fwsData: {},
      djList: [],
      fwsnameDj: "",
    });
    this.openDJ();
  },
  openDJ() {
    this.setData({
      djShow: !this.data.djShow,
    });
  },
  openEdit() {
    this.setData({
      followedit: !this.data.followedit,
    });
  },
  // 打卡
  locateBtn: function () {
    this.setData({
      DK: true,
    });
    wx.navigateTo({
      url: `/pages/locate/follow/follow?sortType=${this.data.projectFollow.selectedID}`,
    });
  },
  // 项目延期
  onCloseOutTime() {
    this.setData({
      outXmzShow: !this.data.outXmzShow,
      outXmz: "",
    });
    this.openEdit();
  },
  inputOutTime(e) {
    this.setData({
      outXmz: e.detail,
    });
  },
  onConfirmOutTime() {
    timeOuts({
      xmztsja: this.formatterTime(this.data.outXmz),
      xmbh: this.data.projectDetail.xmbh,
      xmzbh: this.data.xmzbh,
    }).then((res) => {
      wx.showToast({
        title: "项目延期成功",
        icon: "none",
      });
      this.onCloseOutTime();
      this.getDetail();
    });
  },
  clickOrganization(e) {
    let { child } = e.currentTarget.dataset;
    this.setData({
      OrganizationShow: true,
      OrganizationPersen: child,
    });
  },
  closOrg() {
    this.setData({
      OrganizationShow: false,
      OrganizationPersen: { ...{} },
    });
  },
  // 复盘
  getRecoverData() {
    if (
      this.data.projectDetail.rwbsh == 41 ||
      this.data.projectDetail.rwbsh == 48 ||
      this.data.projectDetail.rwbsh == 61 ||
      this.data.projectDetail.rwbsh == 62 ||
      this.data.projectDetail.xmzth == 7
    ) {
      getRecoverList(this.data.projectDetail.xmbh).then((res) => {
        this.setData({
          RecoverList: res.data,
          projectStatus: 5,
        });
      });
    } else {
      wx.showToast({
        title: "尚未开始复盘环节",
        icon: "none",
      });
    }
  },
  addRecoverData() {
    this.setData({
      "RecoverData.xmzbh": this.data.xmzbh,
      "RecoverData.xmzname": this.data.xmzname,
      "RecoverData.khbh": this.data.projectDetail.khbh,
    });
    addRecover(this.data.RecoverData).then(() => {
      this.getDetail();
      this.getRecoverData();
      this.setData({
        RecoverShow: false,
        projectStatus: 5,
      });
    });
  },
  inputValueRecover(e) {
    const param = e.currentTarget.dataset.name; //字段名
    const value = e.detail; //值
    const key = `RecoverData.${param}`;
    // const msg=`checkData.${param}`;
    this.setData({
      [key]: value,
      // [msg]:'' //清空错误提示
    });
  },
  openRecover(e) {
    let { sffp, cyname } = e.currentTarget.dataset;
    if (sffp == 1) {
      console.log(this.data.sffp, this.data.RecoverNr);

      this.data.RecoverList.forEach((item) => {
        if (item.xmzname == cyname) {
          this.setData({
            RecoverNr: item,
            RecoverShow: !this.data.RecoverShow,
            sffp: sffp,
          });
        }
      });
    } else {
      this.setData({
        RecoverData: {
          xmbh: this.data.projectDetail.xmbh,
          xmmc: this.data.projectDetail.xmmc,
          tname: this.data.Info.jname,
          sffp: sffp,
        },
        sffp: sffp,
        RecoverShow: !this.data.RecoverShow,
      });
    }

    console.log(this.data.sffp, this.data.RecoverNr);
  },

  // 项目落地
  oncloseGround() {
    this.setData({
      groundShow: false,
    });
  },
  openGround() {
    if (
      this.data.projectDetail.rwbsh == 41 ||
      this.data.projectDetail.rwbsh == 48 ||
      this.data.projectDetail.rwbsh == 61 ||
      this.data.projectDetail.rwbsh == 62 ||
      this.data.projectDetail.xmzth == 7
    ) {
      getGround(
        this.data.projectDetail.xmbh,
        this.data.projectDetail.xmfl
      ).then((res) => {
        this.setData({
          groundData: res.data[0] ? res.data[0] : {},
          projectStatus: 4,
        });
      });
    } else {
      wx.showToast({
        title: "项目落地操作请通过数据平台来操作",
        icon: "none",
      });
    }
  },
  // 快速新增
  onPush() {
    try {
      this.data.systemInfo.xmmc === "" || this.data.systemInfo.xmsq === ""
        ? wx.showToast({
            title: "请填写必填项",
            icon: "error",
            duration: 2000, //持续的时间
          })
        : this.Add();
    } catch (error) {
      console.log(error);
    }
  },

  Add() {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let xmztsja = 24 * 60 * 60 * 1000 * 15;
    let JZtime = new Date(time + xmztsja);
    let jz_time = `${JZtime.getFullYear()}-${
      JZtime.getMonth() + 1 < 10
        ? "0" + (JZtime.getMonth() + 1)
        : JZtime.getMonth() + 1
    }-${JZtime.getDate() < 10 ? "0" + JZtime.getDate() : JZtime.getDate()}`;
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    this.setData({
      "systemInfo.bbsj": bbTime,
      "systemInfo.tjsj": `${bbTime} ${tjTime}`,
      "systemInfo.xmztsja": `${jz_time} ${tjTime}`,
      "systemInfo.tkjzsj": `${jz_time} ${tjTime}`,
      "systemInfo.khbh": this.data.projectDetail.khbh,
      "systemInfo.qymc": this.data.enterpriseDetail.qymc,
      "systemInfo.xmly": "已提报项目流转",
    });
    addFastPrograms(this.data.systemInfo)
      .then((res) => {
        wx.showToast({
          title: "新增成功，请填写补充资料",
          icon: "none",
        });
        setTimeout(() => {
          this.setData({
            showDialog: true,
          });
        }, 1000);
      })
      .then(() => {
        addOperateLog({
          type: 1,
          khbh: "暂无",
          xmbh: this.data.systemInfo.xmbh,
          xmmc: this.data.systemInfo.xmmc,
          bm: this.data.systemInfo.bm,
          tname: this.data.systemInfo.tname,
          tjsj: this.data.systemInfo.tjsj,
        });
      });
    this.setData({
      createdFormProject: false,
      GocreatedShow: true,
    });
  },
  // 是否前往新项目
  goNewProject() {
    wx.redirectTo({
      url: `/pages/programs/detail/detail?xmbh=${this.data.systemInfo.xmbh}`,
    });
    wx.setStorageSync("xmzbh", 123);
    wx.setStorageSync("xmzname", 123);
  },
  goOnDown() {
    this.setData({
      createdFormProject: false,
      createdShow: false,
    });
  },

  onConfirm(event) {
    const { picker, value, index } = event.detail;
    this.setData({
      "systemInfo.xmfl": value,
    });
    this.onCancel();
  },
  openPick() {
    this.setData({
      pickerAddShow: true,
    });
  },
  onRest() {
    this.setData({
      systemInfo: {
        ...{},
      },
      createdFormProject: false,
    });
  },
  onCancel() {
    this.setData({
      pickerAddShow: false,
    });
  },
  inputValueSystem(e) {
    const param = e.currentTarget.dataset.name; //字段名
    const value = e.detail; //值
    const key = `systemInfo.${param}`;
    // const msg=`checkData.${param}`;
    this.setData({
      [key]: value,
      // [msg]:'' //清空错误提示
    });
  },
  opencreatedProject() {
    if (!this.data.projectDetail.khbh) {
      wx.showToast({
        title: "当前暂未关联相关企业",
        icon: "none",
      });
    } else {
      this.setData({
        createdShow: true,
      });
    }
  },
  gocreated() {
    let timestamp = Date.parse(new Date());
    let date = new Date(timestamp);
    //获取年份
    let Y = date.getFullYear();
    //获取月份
    let M =
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1;

    let rand = "";
    for (let i = 0; i < 3; i++) {
      let r = Math.floor(Math.random() * 10);
      rand += r;
    }
    let Data = {
      bs: 1,
      jgdmh: this.data.enterpriseDetail.jdgmh
        ? this.data.enterpriseDetail.jdgmh
        : "",
      xmfl: "载体项目", //项目类别
      bm: this.data.Info.bm, //部门
      tname: this.data.Info.jname, //报备人员
      rybh: this.data.Info.rybh, //人员编号
      xmbh: `xmbh${Y}${M}${rand}`, //项目编号
      xmmc: "", //项目名称
      xmsq: "", //项目诉求
      //  xmly: "", //项目来源
      bID: this.data.Info.id, //报备人id
      bbsj: "", //报备时间，不显示字段，提交表单时自动生成当前时间YYY-MM-DD hh:mm:ss
      tjsj: "",
      xmztsja: "",
      bsa: this.data.Info.bsa,
    };
    this.setData({
      createdFormProject: true,
      systemInfo: Data,
    });
  },
  onclosecreated() {
    this.setData({
      createdShow: false,
    });
  },
  onChangepolicyNum(e) {
    this.setData({
      policyNum: e.detail,
    });
  },
  onClickpolicyNum(e) {
    this.setData({
      policyNum: e.currentTarget.dataset.name,
    });
  },
  onCloseturnover() {
    this.setData({
      turnoverShowOne: false,
      turnoverShowTwo: false,
      policyShow: false,
      evaluateShow: false,
    });
  },
  goturnover() {
    folllowRiever({
      xmbh: this.data.projectDetail.xmbh,
      xmmc: this.data.projectDetail.xmmc,
      tname: this.data.projectDetail.tname,
      bm: this.data.projectDetail.bm,
    }).then((res) => {
      let time = new Date().getTime();
      //将时间戳格式转换成年月日时分秒
      let date = new Date(time);
      let bbTime = `${date.getFullYear()}-${
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1
      }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
      let tjTime = `${
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
      }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
      }`;
      getevaluateList(this.data.projectDetail.xmfl)
        .then((res) => {
          res.data.forEach((item) => {
            addDingLog({
              type: 11,
              tnamea: item.nr,
              xmfl: this.data.projectDetail.xmfl,
              tnameb: this.data.Info.jname,
              xmmc: this.data.projectDetail.xmmc,
              tjsj: `${bbTime} ${tjTime}`,
            });
console.log('item',item)
            DDNotify({
              userId: item.nb,
              xmbh: this.data.projectDetail.xmbh,
              title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
              content: `该项目发起流转，您可在5日内领取该项目，组建项目组推进落实`,
            });
          });
        })
        .then(() => {
          this.setData({
            evaluateShow: false,
            turnoverShowOne: false,
            turnoverShowTwo: false,
            policyShow: false,
          });
          this.getDetail();
        });
    });
  },
  turnoverFuntion() {
    if (this.data.projectDetail.xmfl == "政策项目") {
      console.log(this.data.enterpriseDetail.nss);
      if (this.data.enterpriseDetail.nss - 0 >= 100) {
        this.setData({
          policyNum: "预计税收100万（含）以上",
        });
      } else {
        this.setData({
          policyNum: "预计税收100万以下",
        });
      }
      this.setData({
        evaluateShow: false,
        policyShow: true,
      });
    } else if (
      this.data.projectDetail.xmfl == "产业项目" ||
      this.data.projectDetail.xmfl == "科技项目"
    ) {
      this.setData({
        turnoverShowOne: true,
        policyShow: false,
        turnoverShowTwo: false,
      });
    } else {
      this.setData({
        evaluateShow: false,
        turnoverShowTwo: true,
      });
    }
  },
  onQySearchChange(e) {
    this.setData({
      "contactsEnterpriseData.qymc": e.detail,
    });
  },
  onQySearch() {
    if (this.data.contactsEnterpriseData.qymc.length < 4) {
      wx.showToast({
        title: "关键词长度不得小于4字符",
        icon: "none",
      });
    } else {
      searchQy(this.data.contactsEnterpriseData.qymc).then((res) => {
        this.setData({
          QyList: res.data,
        });
      });
    }
  },
  onQySelect(e) {
    this.setData({
      "contactsEnterpriseData.qymc": e.detail,
    });
  },
  onClickQyItem(e) {
    let { qymc, khbh, xmly, bs, jgdmh } = e.currentTarget.dataset;
    if (bs == 1) {
      getEnterpriseContacts(khbh).then((res) => {
        if (res.data == 1) {
          wx.showToast({
            title: "当前企业处于流转阶段",
            icon: "none",
          });
        } else {
          this.setData({
            "contactsEnterpriseData.qymc": qymc,
            "contactsEnterpriseData.bs": bs,
            "contactsEnterpriseData.khbh": khbh,
            "contactsEnterpriseData.xmly": xmly,
            "contactsEnterpriseData.xmbh": this.data.projectDetail.xmbh,
            "contactsEnterpriseData.jgdmh": jgdmh,
          });
        }
      });
    } else {
      this.setData({
        "contactsEnterpriseData.qymc": qymc,
        "contactsEnterpriseData.bs": bs,
        "contactsEnterpriseData.khbh": khbh,
        "contactsEnterpriseData.xmly": xmly,
        "contactsEnterpriseData.xmbh": this.data.projectDetail.xmbh,
        "contactsEnterpriseData.jgdmh": jgdmh,
      });
    }
  },

  updateXmsq() {
    this.setData({
      "projectDetail.xmsq": this.data.xmsq,
    });
    updatePrograms(this.data.projectDetail).then((res) => {
      wx.showToast({
        title: "更新项目诉求成功",
        icon: "none",
      });
      this.getDetail();
      this.clickXmsq();
    });
  },
  inputSq(e) {
    this.setData({
      xmsq: e.detail,
    });
  },
  clickXmsq() {
    this.setData({
      xmsqShow: !this.data.xmsqShow,
      xmsq: "",
    });
  },
  Abandon(e) {
    let { type } = e.target.dataset;
    this.setData({
      AbandonShow: true,
      AbandonType: type,
    });
    this.openEdit();
  },
  addAbandon() {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    this.data.AbandonType == "TK"
      ? torkAbandon({
          xmbh: this.data.projectDetail.xmbh,
          gjnr: this.data.AbandonContent,
          tjsj: `${bbTime} ${tjTime}`,
          jname: this.data.Info.jname,
          tname: this.data.projectDetail.tname,
          xmmc: this.data.projectDetail.xmmc,
          bm: this.data.Info.bm,
          xmzbh: this.data.xmzbh,
          xmzname: this.data.xmzname,
        }).then(() => {
          wx.showToast({
            title: "拓客放弃成功",
            icon: "none",
          });
          this.CloseAbandon();
        })
      : followAbandon({
          xmbh: this.data.projectDetail.xmbh,
          gjnr: this.data.AbandonContent,
          tjsj: `${bbTime} ${tjTime}`,
          jname: this.data.Info.jname,
          tname: this.data.projectDetail.tname,
          xmmc: this.data.projectDetail.xmmc,
          bm: this.data.Info.bm,
          xmzbh: this.data.xmzbh,
          xmzname: this.data.xmzname,
        }).then(() => {
          wx.showToast({
            title: "跟进放弃成功",
            icon: "none",
          });
          // wx.navigateTo({
          //   url: '/pages/programs/forward/forward',
          // })
          this.getDetail();
          this.CloseAbandon();
        });
  },
  inputValueAbandon(e) {
    let param = e.currentTarget.dataset.name; //字段名
    let value = e.detail; //值

    this.setData({
      AbandonContent: value,
    });
  },
  CloseAbandon() {
    this.setData({
      AbandonShow: false,
      AbandonContent: "",
    });
    this.onLoad({
      xmbh: this.data.projectDetail.xmbh,
    });
  },
  goGround() {
    this.setData({
      projectStatus: 3,
    });
    // if (this.data.projectDetail.rwbsh == 41) {
    //   wx.showToast({
    //     title: "请前往数据平台进行项目落地",
    //     icon: "none",
    //   });
    // }
  },
  openProgress() {
    let INFO = wx.getStorageSync("userInfoMy");

    this.setData({
      progressShow: true,
      "progressData.xmbh": this.data.projectDetail.xmbh,
      "progressData.tname": INFO.jname,
    });
  },
  addProgress() {
    if (this.data.progressData.gjnr == "") {
      wx.showToast({
        title: "请填写进展反馈",
        icon: "error",
        duration: 2000, //持续的时间
      });
      return;
    }
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;

    this.setData({
      "progressData.tjsj": `${bbTime} ${tjTime}`,
    });
    addProgress(this.data.progressData).then((res) => {
      wx.showToast({
        title: "进展反馈添加完成",
      });
    });
    this.CloseProgress();
    this.getProgress();
  },
  getProgress() {
    getProgress(this.data.projectDetail.xmbh).then((res) => {
      this.setData({
        progressList: res,
      });
    });
  },
  CloseProgress() {
    this.setData({
      progressShow: false,
      "progressData.gjnr": "",
    });
  },
  getFollow() {
    getFollow(this.data.projectDetail.xmbh, this.data.projectDetail.xmID).then(
      (res) => {
        this.setData({
          followList: res,
        });
      }
    );
  },
  addFollow() {
    let user = wx.getStorageSync("userInfoMy");
    this.setData({
      "projectFollow.xmbh": this.data.projectDetail.xmbh,
      "projectFollow.khbh": this.data.enterpriseDetail.khbh
        ? this.data.enterpriseDetail.khbh
        : "暂无",
      "projectFollow.rybh": user.rybh,
      "projectFollow.bm": user.bm,
      "projectFollow.tname": user.jname,
      "projectFollow.xmzbh": wx.getStorageSync("xmzbh"),
    });
    for (const key in this.data.projectFollow) {
      if (this.data.projectFollow[key] == "") {
        console.log(key);
        if (key != "zsph") {
          wx.showToast({
            title: "请填写必填项",
            icon: "error",
            duration: 1000, //持续的时间
          });
          return;
        }
      } else {
        if (key == "gjlx" && this.data.projectFollow.selectedID != 3) {
          console.log(key == "gjlx" && this.data.projectFollow.selectedID != 3);
          if (this.data.DK == false) {
            wx.showToast({
              title: "请填写必填项",
              icon: "error",
              duration: 1000, //持续的时间
            });
            return;
          }
        }
      }
    }
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;

    this.setData({
      "projectFollow.tjsj": `${bbTime} ${tjTime}`,
      "projectFollow.gjsj": this.formatterTime2(this.data.projectFollow.gjsj),
      "projectFollow.xcsj": this.formatterTime(this.data.projectFollow.xcsj),
      "projectFollow.xmzname": this.data.xmzname,
    });
    getProjectFollow(this.data.projectFollow).then((res) => {
      let location = wx.getStorageSync("nowaddress");
      let image = wx.getStorageSync("addressgj");

      theonefollow({
        qymc: this.data.enterpriseDetail.qymc,
        bm: this.data.Info.bm,
        zsy: this.data.Info.jname,
        jdsm: `添加了客户${this.data.enterpriseDetail.qymc}的跟进记录`,
        dksj: `${bbTime} ${tjTime}`,
        scsj: `${bbTime}`,
        image: image,
        address: location,
        khbh: this.data.projectDetail.khbh
          ? this.data.projectDetail.khbh
          : this.data.science.kzID,
        gjid: res.data.gjID,
      }).then(() => {
        hgjfilesfollow({
          mc: image,
          hid: this.data.projectDetail.xmID,
          FileUrl: image,
          AddTime: `${bbTime} ${tjTime}`,
          gid: res.data.gjID,
          khbh: this.data.projectDetail.khbh
            ? this.data.projectDetail.khbh
            : this.data.science.kzID,
          tname: this.data.Info.jname,
        }).then(() => {
          wx.showToast({
            title: "跟进记录添加完成",
          });
          wx.removeStorageSync("nowaddress");
          wx.removeStorageSync("addressgj");
          this.Closefollow();
          this.getDetail();
        });
      });
    });
  },
  formatterTime(time) {
    let date = new Date(time);
    let year = date.getFullYear();
    let month = ("0" + (date.getMonth() + 1)).slice(-2);
    let day = ("0" + date.getDate()).slice(-2);
    let hours = ("0" + date.getHours()).slice(-2);
    let minutes = ("0" + date.getMinutes()).slice(-2);
    let seconds = ("0" + date.getSeconds()).slice(-2);
    let formattedTime = year + "-" + month + "-" + day;
    return formattedTime;
  },
  formatterTime2(time) {
    let date = new Date(time);
    let year = date.getFullYear();
    let month = ("0" + (date.getMonth() + 1)).slice(-2);
    let day = ("0" + date.getDate()).slice(-2);
    let hours = ("0" + date.getHours()).slice(-2);
    let minutes = ("0" + date.getMinutes()).slice(-2);
    let seconds = ("0" + date.getSeconds()).slice(-2);
    let formattedTime =
      year +
      "-" +
      month +
      "-" +
      day +
      " " +
      hours +
      ":" +
      minutes +
      ":" +
      seconds;
    return formattedTime;
  },
  Closefollow() {
    this.setData({
      DK: false,
      projectFollow: {
        fwrname: "",
        // zsph: "",
        selectedID: 1,
        gjlx: "上门拜访",
        khjd: "初次接触",
        gjsj: "",
        gjnr: "",
        xcsj: "",
        xmbh: "",
        khbh: "",
        rybh: "",
        bm: "",
        tname: "",
        xmzbh: "",
      },
      FollowShow: false,
    });
  },
  onClickXcsj() {
    this.setData({
      xcsjShow: true,
    });
  },
  onClickGjsj() {
    this.setData({
      gjsjShow: true,
    });
  },
  onClickGjlx() {
    this.setData({
      pickerShow: true,
    });
  },
  onClickkhjd() {
    this.setData({
      khjdShow: true,
    });
  },
  openFollow() {
    let time = new Date().getTime();
    this.setData({
      FollowShow: true,
      "projectFollow.gjsj": time,
      "projectFollow.xcsj": time,
    });
    this.openEdit();
  },
  onCloseFollow() {
    this.setData({
      showfwrname: false,
      showGjsj: false,
      showXcsj: false,
      pickerShow: false,
      khjdShow: false,
      gjsjShow: false,
      xcsjShow: false,
      showTaskInfo: false,
    });
  },
  onClickFwsname(e) {
    this.setData({
      showfwrname: true,
    });
  },
  // 面板变换
  onChangeCollapse(event) {
    this.setData({
      activeName: event.detail,
    });
  },
  // 按钮选中切换阶段
  checkStatus(e) {
    let status = e.currentTarget.dataset.status;
    switch (status) {
      case "1":
        setTimeout(() => {
          this.setData({
            projectStatus: status,
          });
        }, 100);
        break;
      case "2":
        setTimeout(() => {
          this.setData({
            projectStatus: status,
          });
        }, 100);
        break;
      case "3":
        if (
          this.data.projectDetail.rwbsh == 41 ||
          this.data.projectDetail.rwbsh == 48 ||
          this.data.projectDetail.rwbsh == 61 ||
          this.data.projectDetail.rwbsh == 62 ||
          this.data.projectDetail.xmzth == 7 ||
          this.data.projectDetail.xmzth == 23
        ) {
          this.getProjectMember();
          this.getFollow();
          this.getProgress();
          setTimeout(() => {
            this.setData({
              projectStatus: status,
            });
          }, 100);
        } else {
          wx.showToast({
            title: "尚未开始跟进阶段",
            icon: "none",
          });
        }

        break;
      case "4":
        this.openGround();
        if (this.data.projectDetail.xmzth >= 6) {
          setTimeout(() => {
            this.setData({
              projectStatus: status,
            });
          }, 100);
        }
        break;
      case "5":
        this.getRecoverData();

        if (this.data.projectDetail.xmzth > 6) {
          setTimeout(() => {
            this.setData({
              projectStatus: status,
            });
          }, 100);
        }
        break;

      default:
        break;
    }
  },
  getProjectMember() {
    getProjectMember(this.data.projectDetail.xmbh).then((res) => {
      this.setData({
        projectMember: res.data,
      });
    });
    searchConnection(this.data.projectDetail.xmbh).then((res) => {
      this.setData({
        connectionList: res.data,
      });
    });
  },
  addMember(e) {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    let { type } = e.target.dataset;
    type == 1
      ? this.setData({
          MemberData: {
            rybh: this.data.Info.rybh,
            xmbh: this.data.projectDetail.xmbh,
            xmfl: this.data.projectDetail.xmfl,
            xmzcy: this.data.Info.jname,
            cyname: this.data.Info.jname,
            xmzbh: this.data.xmzbh,
            xmzname: this.data.xmzname,
            tname: this.data.projectDetail.tname,
            tjsj: `${bbTime} ${tjTime}`,
            bsa: this.data.Info.bsa,
          },
        })
      : this.setData({
          MemberData: {
            rybh: this.data.MemberData.rybh,
            xmbh: this.data.projectDetail.xmbh,
            xmfl: this.data.projectDetail.xmfl,
            xmzcy: this.data.Mname,
            cyname: this.data.Mname,
            tname: this.data.projectDetail.tname,
            xmzbh: this.data.xmzbh,
            xmzname: this.data.xmzname,
            tjsj: `${bbTime} ${tjTime}`,
            bsa: this.data.Info.bsa,
          },
        });
    addMember(this.data.MemberData).then((res) => {
      if (type == 1) {
        addDingLog({
          type: 7,
          tnamea: this.data.projectDetail.tname,
          tnameb: this.data.MemberData.cyname,
          xmfl: this.data.projectDetail.xmfl,
          xmmc: this.data.projectDetail.xmmc,
          tjsj: `${bbTime} ${tjTime}`,
        });
        DDNotify({
          userId: this.data.projectDetail.rybh,
          xmbh: this.data.projectDetail.xmbh,
          title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
          content: `${this.data.MemberData.cyname}已主动加入项目组，期待和您共同促进项目尽快落地
          `,
        });
      } else {
        addDingLog({
          type: 9,
          tnamea: this.data.projectDetail.tname,
          tnameb: this.data.MemberData.cyname,
          xmfl: this.data.projectDetail.xmfl,
          xmmc: this.data.projectDetail.xmmc,
          tjsj: `${bbTime} ${tjTime}`,
        });
        DDNotify({
          userId: this.data.projectDetail.rybh,
          xmbh: this.data.projectDetail.xmbh,
          title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
          content: `${this.data.MemberData.cyname}已被邀请加入项目组，期待和您共同促进项目尽快落地
          `,
        });
      }
      this.onCloseMeber();
      // this.onLoad({
      //   xmbh: this.data.projectDetail.xmbh
      // });

      this.getProjectMember();
      this.setData({
        MemberList: [],
      });
    });
  },
  openaddMember(e) {
    let { xmzbh } = e.currentTarget.dataset;
    this.setData({
      MemberShow: true,
      xmzbh: xmzbh,
      xmzname: this.data.xmzname,
    });
  },
  onSearchChange(e) {
    this.setData({
      Mname: e.detail,
    });
  },
  onSearch() {
    getMemberList(this.data.Mname).then((res) => {
      this.setData({
        MemberList: res.data,
      });
    });
  },
  onSelect(e) {
    this.setData({
      Mname: e.detail,
    });
  },
  onClickItem(e) {
    let { name, rybh } = e.currentTarget.dataset;
    this.setData({
      Mname: name,
      "MemberData.rybh": rybh,
    });
  },

  // 领取项目
  pullProject() {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    // 不同项目类型 + time
    let kztime = new Date(time + 24 * 60 * 60 * 1000 * 60);
    let cztime = new Date(time + 24 * 60 * 60 * 1000 * 90);
    let qttime = new Date(time + 24 * 60 * 60 * 1000 * 5);

    let kzTime = `${kztime.getFullYear()}-${
      kztime.getMonth() + 1 < 10
        ? "0" + (kztime.getMonth() + 1)
        : kztime.getMonth() + 1
    }-${kztime.getDate() < 10 ? "0" + kztime.getDate() : kztime.getDate()}`;
    let czTime = `${cztime.getFullYear()}-${
      cztime.getMonth() + 1 < 10
        ? "0" + (cztime.getMonth() + 1)
        : cztime.getMonth() + 1
    }-${cztime.getDate() < 10 ? "0" + cztime.getDate() : cztime.getDate()}`;
    let qtTime = `${qttime.getFullYear()}-${
      qttime.getMonth() + 1 < 10
        ? "0" + (qttime.getMonth() + 1)
        : qttime.getMonth() + 1
    }-${qttime.getDate() < 10 ? "0" + qttime.getDate() : qttime.getDate()}`;

    let INFO = wx.getStorageSync("userInfoMy");

    pullProject({
      xmbh: this.data.projectDetail.xmbh,
      xmfl: this.data.projectDetail.xmfl,
      xmmc: this.data.projectDetail.xmmc,
      xmzfzr: INFO.jname,
      xmzgj: this.data.projectDetail.xmzgj + 1,
      bsa: INFO.bsa,
      rybh: INFO.rybh,
      rybh2: this.data.projectDetail.rybh,
      xmzbh: INFO.rybh,
      xmzkssj: `${bbTime} ${tjTime}`,
      cyname: INFO.jname,
      tname: this.data.projectDetail.tname,
      zfcbjsa: `${qtTime} ${tjTime}`,
      xmztsja:
        this.data.projectDetail.xmfl == "人才项目" ||
        this.data.projectDetail.xmfl == "科技项目" ||
        this.data.projectDetail.xmfl == "产业项目"
          ? `${czTime} ${tjTime}`
          : `${kzTime} ${tjTime}`,
      tjsj: `${bbTime} ${tjTime}`,
    }).then((res) => {
      if (res.status == "200") {
        wx.showToast({
          title: "领取成功",
        });
        addOperateLog({
          type: 10,
          xmbh: this.data.projectDetail.xmbh,
          khbh: this.data.enterpriseDetail.khbh,
          xmmc: this.data.projectDetail.xmmc,
          bm: this.data.Info.bm,
          tname: this.data.Info.jname,
          tjsj: `${bbTime} ${tjTime}`,
        });
        addDingLog({
          type: 8,
          tnamea: this.data.projectDetail.tname,
          tnameb: this.data.Info.jname,
          xmmc: this.data.projectDetail.xmmc,
          xmfl: this.data.projectDetail.xmfl,

          tjsj: `${bbTime} ${tjTime}`,
        });
        DDNotify({
          userId: this.data.projectDetail.rybh,
          xmbh: this.data.projectDetail.xmbh,
          title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
          content: `${this.data.Info.jname}已领取项目跟进任务，您已默认加入其跟进小组，请及时沟通共促项目落地`,
        });
        DDNotify({
          userId: this.data.Info.rybh,
          xmbh: this.data.projectDetail.xmbh,
          title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
          content: `您已领取该项目跟进任务，请组建项目跟进小组，并在七天内完成首次跟进记录提报`,
        });
        setTimeout(() => {
          wx.setStorageSync("xmzbh", this.data.Info.rybh);
          wx.setStorageSync("xmzname", this.data.Info.jname);

          this.onLoad({
            xmbh: this.data.projectDetail.xmbh,
          });
        }, 1000);
      }
    });
  },
  applytask() {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;

    // 不同项目类型 + time
    let kztime = new Date(time + 24 * 60 * 60 * 1000 * 60);
    let cztime = new Date(time + 24 * 60 * 60 * 1000 * 90);
    let qttime = new Date(time + 24 * 60 * 60 * 1000 * 5);

    let kzTime = `${kztime.getFullYear()}-${
      kztime.getMonth() + 1 < 10
        ? "0" + (kztime.getMonth() + 1)
        : kztime.getMonth() + 1
    }-${kztime.getDate() < 10 ? "0" + kztime.getDate() : kztime.getDate()}`;
    let czTime = `${cztime.getFullYear()}-${
      cztime.getMonth() + 1 < 10
        ? "0" + (cztime.getMonth() + 1)
        : cztime.getMonth() + 1
    }-${cztime.getDate() < 10 ? "0" + cztime.getDate() : cztime.getDate()}`;
    let qtTime = `${qttime.getFullYear()}-${
      qttime.getMonth() + 1 < 10
        ? "0" + (qttime.getMonth() + 1)
        : qttime.getMonth() + 1
    }-${qttime.getDate() < 10 ? "0" + qttime.getDate() : qttime.getDate()}`;

    this.setData({
      "taskData.pgf":
        this.data.taskData.a1 +
        this.data.taskData.a2 +
        this.data.taskData.a3 +
        this.data.taskData.a4 +
        this.data.taskData.a5,
      "taskData.wcsj": `${bbTime} ${tjTime}`,
      "taskData.sfzg": this.data.projectDetail.sfzg,
      "taskData.sfwc": 1,
      "taskData.bsa": this.data.projectDetail.xmzcy,
      "taskData.xmpgwcsj": `${bbTime} ${tjTime}`,
    });

    if (
      this.data.projectDetail.xmfl == "科技项目" ||
      this.data.projectDetail.xmfl == "产业项目"
    ) {
      this.setData({
        "taskData.xmztsja": `${czTime} ${tjTime}`,
        "taskData.zfcbjsa": `${qtTime} ${tjTime}`,
      });
    } else {
      this.setData({
        "taskData.zfcbjsa": `${qtTime} ${tjTime}`,
        "taskData.xmztsja": `${kzTime} ${tjTime}`,
      });
    }
    applytask(this.data.taskData).then(() => {
      gettaskEvaluation(this.data.projectDetail.xmbh).then((res) => {
        let tasklist = res.data;
        let tasklistN = [];

        tasklist.forEach((item, index) => {
          if (item.pgjb == 1) {
            tasklistN.unshift(item);
          } else {
            tasklistN.push(item);
          }
        });
        this.setData({
          evaluation: tasklistN,
          taskInfo: res.info[0],
        });

        this.setData({
          "jind.wc":
            Math.round(
              (this.data.taskInfo.pgwcs / this.data.taskInfo.pgrzs) * 10000
            ) / 100.0,
          "jind.tg":
            Math.round(
              (this.data.taskInfo.tgs / (this.data.taskInfo.pgrzs + 1)) * 10000
            ) / 100.0,
        });

        if (
          this.data.taskInfo.pgrzs == this.data.taskInfo.pgwcs &&
          this.data.taskInfo.tgs >= this.data.taskInfo.btgs
        ) {
          addOperateLog({
            type: 8,
            xmbh: this.data.projectDetail.xmbh,
            khbh: this.data.enterpriseDetail.khbh,
            xmmc: this.data.projectDetail.xmmc,
            bm: this.data.Info.bm,
            tname: this.data.Info.jname,
            pgjg: this.data.taskData.sftg == 1 ? "通过" : "不通过",
            tjsj: `${bbTime} ${tjTime}`,
          });
          addDingLog({
            type: 1,
            tnamea: this.data.projectDetail.tname,
            tnameb: this.data.Info.jname,
            sftg: this.data.taskData.sftg,
            xmmc: this.data.projectDetail.xmmc,
            tjsj: this.data.taskData.wcsj,
          });
          addDingLog({
            type: 2,
            tnamea: this.data.projectDetail.tname,
            tnameb: this.data.Info.jname,
            sftg: this.data.taskData.sftg,
            xmmc: this.data.projectDetail.xmmc,
            tjsj: this.data.taskData.wcsj,
          });
          DDNotify({
            userId: this.data.projectDetail.rybh,
            xmbh: this.data.projectDetail.xmbh,
            title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
            content: `${this.data.Info.jname}于${
              this.data.taskData.wcsj
            }对该项目进行评估，评估结果：${
              this.data.taskData.sftg == 1 ? "通过" : "不通过"
            }`,
          });
          DDNotify({
            userId: this.data.projectDetail.rybh,
            xmbh: this.data.projectDetail.xmbh,
            title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
            content: `评估组于${this.data.taskData.wcsj}完成对该项目的评估，评估结果：通过`,
          });
          addDingLog({
            type: 4,
            tnamea: this.data.projectDetail.tname,
            xmfl: this.data.projectDetail.xmfl,
            tnameb: this.data.Info.jname,
            sftg: this.data.taskData.sftg,
            xmmc: this.data.projectDetail.xmmc,
            tjsj: `${bbTime} ${tjTime}`,
          });
          DDNotify({
            userId: this.data.projectDetail.rybh,
            xmbh: this.data.projectDetail.xmbh,
            title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
            content: `该项目已通过评估;请您及时查看跟进`,
          });
          getevaluateList(this.data.projectDetail.xmfl)
            .then((res) => {
              res.data.forEach((item) => {
                addDingLog({
                  type: 6,
                  tnamea: item.nr,
                  xmfl: this.data.projectDetail.xmfl,
                  tnameb: this.data.Info.jname,
                  sftg: this.data.taskData.sftg,
                  xmmc: this.data.projectDetail.xmmc,
                  tjsj: `${bbTime} ${tjTime}`,
                });

                DDNotify({
                  userId: item.nb,
                  xmbh: this.data.projectDetail.xmbh,
                  title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
                  content: `该项目已通过评估，您可在5日内领取该项目，组建项目组推进落实`,
                });
              });
            })
            .then(() => {
              this.onClose();
              setTimeout(() => {
                this.onLoad({
                  xmbh: this.data.projectDetail.xmbh,
                });
              }, 1000);
            });
        } else if (
          this.data.taskInfo.pgrzs == this.data.taskInfo.pgwcs &&
          this.data.taskInfo.tgs < this.data.taskInfo.btgs
        ) {
          addOperateLog({
            type: 9,
            xmbh: this.data.projectDetail.xmbh,
            khbh: this.data.enterpriseDetail.khbh,
            xmmc: this.data.projectDetail.xmmc,
            bm: this.data.Info.bm,
            tname: this.data.Info.janme,
            pgjg: this.data.taskData.sftg == 1 ? "通过" : "不通过",
            tjsj: this.data.taskData.wcsj,
          });
          DDNotify({
            userId: this.data.projectDetail.rybh,
            xmbh: this.data.projectDetail.xmbh,
            title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
            content: `评估组于${this.data.taskData.wcsj}完成对该项目的评估，评估结果：不通过`,
          });
          addDingLog({
            type: 2,
            tname: this.data.Info.jname,
            sftg: this.data.taskData.sftg,
            xmmc: this.data.projectDetail.xmmc,
            tjsj: this.data.taskData.wcsj,
          }).then(() => {
            this.onClose();

            setTimeout(() => {
              this.onLoad({
                xmbh: this.data.projectDetail.xmbh,
              });
            }, 1000);
          });
        } else {
          addOperateLog({
            type: 7,
            xmbh: this.data.projectDetail.xmbh,
            khbh: this.data.enterpriseDetail.khbh,
            xmmc: this.data.projectDetail.xmmc,
            bm: this.data.Info.bm,
            tname: this.data.Info.jname,
            pgjg: this.data.taskData.sftg == 1 ? "通过" : "不通过",
            tjsj: this.data.taskData.wcsj,
          });
          DDNotify({
            userId: this.data.projectDetail.rybh,
            xmbh: this.data.projectDetail.xmbh,
            title: `${this.data.projectDetail.xmfl}-${this.data.projectDetail.xmmc}`,
            content: `${this.data.Info.jname}于${
              this.data.taskData.wcsj
            }对该项目进行评估，评估结果：${
              this.data.taskData.sftg == 1 ? "通过" : "不通过"
            }`,
          });
          addDingLog({
            type: 1,
            tnamea: this.data.projectDetail.tname,
            tnameb: this.data.Info.jname,
            sftg: this.data.taskData.sftg,
            xmmc: this.data.projectDetail.xmmc,
            tjsj: this.data.taskData.wcsj,
          }).then(() => {
            this.onClose();

            setTimeout(() => {
              this.onLoad({
                xmbh: this.data.projectDetail.xmbh,
              });
            }, 1000);
          });
        }
        wx.showToast({
          title: "评估完成",
          icon: "none",
        });
      });
    });
  },
  openTask(e) {
    this.setData({
      showTask: true,
      "taskData.pgname": e.target.dataset.pgname,
      "taskData.xmbh": e.target.dataset.xmbh,
      pgjb: e.target.dataset.pgjb,
    });
  },
  openTaskInfo(e) {
    let task = e.target.dataset.item;
    this.setData({
      showTaskInfo: true,
      taskData: { ...task },
      pgsm: task.pgsm,
    });
  },
  onClose(e) {
    this.setData({
      pgsm: "",
      showTask: false,
      showTaskInfo: false,
      radio: "2",
      taskData: {
        a1: 1,
        a2: 1,
        a3: 1,
        a4: 1,
        a5: 1,
        pgf: 5,
        pgsm: "",
        sfwc: "",
        sftg: "2",
        xmbh: "",
        pgname: "",
      },
    });
  },
  onCloseMeber(e) {
    this.setData({
      MemberShow: false,
      Mname: "",
    });
  },
  onClick(event) {
    let { name, title } = event.currentTarget.dataset;
    this.setData({
      radio: name,
      // "taskData.pgsm": title,
    });
    if (name == "1") {
      this.setData({
        "taskData.sfwc": "1",
        "taskData.sftg": name,
      });
    } else if (name == 2) {
      this.setData({
        "taskData.sfwc": "1",
        "taskData.sftg": name,
      });
    }
  },
  onChange(e) {
    this.setData({
      radio: e.detail,
      "taskData.sftg": e.detail,
    });
  },
  inputValueProgress(e) {
    let param = e.currentTarget.dataset.name; //字段名
    let value = e.detail; //值
    let key = `progressData.${param}`;
    this.setData({
      [key]: value,
    });
  },
  inputValueFollow(e) {
    let param = e.currentTarget.dataset.name; //字段名
    let value = e.detail; //值
    if (param == "fwrname" || param == "gjlx" || param == "khjd") {
      value = value.value;
    }

    let key = `projectFollow.${param}`;
    this.setData({
      [key]: value,
    });
    if (param == "gjlx") {
      let selectedID = 1;
      switch (value) {
        case "上门拜访":
          selectedID = 1;
          break;
        case "来访接待":
          selectedID = 2;
          break;
        case "线上拜访":
          selectedID = 3;
          break;

        default:
          break;
      }
      console.log(selectedID);
      this.setData({
        "projectFollow.selectedID": selectedID,
      });
    }
  },
  inputValue(e) {
    let param = e.currentTarget.dataset.name; //字段名
    let value = e.detail; //值
    let key = `taskData.${param}`;
    this.setData({
      [key]: value,
    });
  },
  // onUpdateProject() {
  //   wx.navigateTo({
  //     url: `/pages/programs/add/add?xmbh=${this.data.projectDetail.xmbh}&xmID=${this.data.projectDetail.xmID}`,
  //   });
  // },
  getDetail() {
    this.setData({
      Info: wx.getStorageSync("userInfoMy"),
      xmzname: wx.getStorageSync("xmzname"),
      xmzbh: wx.getStorageSync("xmzbh"),
    });
    let xmInfo = {};
    getProjectDetail(this.data.xmbh, this.data.Info.jname)
      .then((res) => {
        if (res.info.length > 1) {
          res.info.forEach((item) => {
            console.log(item.xmzbh == this.data.xmzbh, xmInfo);
            if (item.xmzbh == this.data.xmzbh) {
              xmInfo = item;
              console.log(item.xmzbh == this.data.xmzbh, xmInfo);
            }
          });
        } else {
          xmInfo = res.info[0];
        }

        let Detail = {
          ...xmInfo,
          ...res.data[0],
        };
        try {
          this.setData({
            projectDetail: { ...Detail },
          });
          if (this.data.projectDetail.xmzth > 4) {
            // this.getRecoverData();
          }
          if (
            this.data.projectDetail.rwbsh == 11 ||
            this.data.projectDetail.rwbsh == 21 ||
            this.data.projectDetail.rwbsh == 51 ||
            this.data.projectDetail.rwbsh == 50 ||
            this.data.projectDetail.rwbsh == 40
          ) {
            this.setData({
              projectStatus: 1,
            });
          } else if (
            this.data.projectDetail.rwbsh == 31 ||
            this.data.projectDetail.rwbsh == 32 ||
            this.data.projectDetail.rwbsh == 38
          ) {
            this.setData({
              projectStatus: 2,
            });
          } else if (
            this.data.projectDetail.rwbsh == 41 ||
            this.data.projectDetail.rwbsh == 48 ||
            this.data.projectDetail.rwbsh == 42 ||
            this.data.projectDetail.rwbsh == 43
          ) {
            this.setData({
              projectStatus: 3,
            });
          } else if (
            this.data.projectDetail.rwbsh == 61 ||
            this.data.projectDetail.rwbsh == 62 ||
            this.data.projectDetail.xmzth == 23
          ) {
            this.setData({
              projectStatus: 5,
            });
          }
        } catch (error) {
          console.log(error);
        }
      })
      .then(() => {
        if (this.data.projectDetail.khbh) {
          getEnterprise(this.data.projectDetail.khbh).then((res) => {
            let Detail = {
              ...res.data[0],
            };
            if (
              Detail.hyfla != "" &&
              Detail.hyfla != null &&
              Detail.hyfla != undefined
            ) {
              Detail.hyfl = `${Detail.hyfla}/${Detail.hyflb}`;
            } else {
              Detail.hyfl = "未补充行业分类";
            }
            this.setData({
              enterpriseDetail: Detail,
            });
          });
          this.setData({
            enterpriseShow: true,
          });
        } else {
          this.setData({
            enterpriseShow: false,
          });
        }

        getrequirement(this.data.xmbh).then((res) => {
          let Detail = {
            ...res.data[0],
          };

          try {
            if (!Detail.xqID) {
              let Rshow = this.data.requirementShow;
              this.setData({
                requirementShow: !Rshow,
              });
            } else {
              this.setData({
                requirement: Detail,
              });
            }
          } catch (error) {
            console.log(error);
          }
        });

        if (
          this.data.projectDetail.xmfl === "人才项目" ||
          this.data.projectDetail.xmfl === "测试项目"
        ) {
          getscience(this.data.xmbh).then((res) => {
            let Detail = {
              ...res.data[0],
            };
            try {
              if (!Detail.kzID) {
                this.setData({
                  scienceShow: false,
                });
              } else {
                if (
                  Detail.hyfla != "" &&
                  Detail.hyfla != null &&
                  Detail.hyfla != undefined
                ) {
                  Detail.hyfl = `${Detail.hyfla}/${Detail.hyflb}`;
                } else {
                  Detail.hyfl = "未补充行业分类";
                }
                this.setData({
                  science: Detail,
                  scienceShow: true,
                });
              }
            } catch (error) {
              console.log(error);
            }
          });
        }
        // 判断必填
        if (this.data.projectDetail.xmzt == "报备") {
          this.getRequireINfo();
        }
        this.getProjectMember();
        this.getFollow();
        this.getProgress();
        try {
          if (this.data.projectDetail.xmpgs != 0) {
            gettaskEvaluation(this.data.projectDetail.xmbh).then((res) => {
              let tasklist = res.data;
              let tasklistN = [];

              tasklist.forEach((item, index) => {
                if (item.pgjb == 1) {
                  tasklistN.unshift(item);
                } else {
                  tasklistN.push(item);
                }
              });
              this.setData({
                evaluation: tasklistN,
                taskInfo: res.info[0],
              });
              this.setData({
                "jind.wc":
                  Math.round(
                    (this.data.taskInfo.pgwcs / this.data.taskInfo.pgrzs) *
                      10000
                  ) / 100.0,
                "jind.tg":
                  Math.round(
                    (this.data.taskInfo.tgs / (this.data.taskInfo.pgrzs + 1)) *
                      10000
                  ) / 100.0,
              });
            });
          }
        } catch (error) {
          console.log(error);
        }
      });
  },

  onEvaluateChange(event) {
    this.setData({
      evaluateRadio: event.detail,
    });
  },

  onClickEvaluate(event) {
    const { name } = event.currentTarget.dataset;
    this.setData({
      evaluateRadio: name,
    });
  },
  btnEvaluate() {
    this.setData({
      evaluateShow: true,
    });
  },
  closeEvaluste() {
    this.setData({
      evaluateShow: false,
      evaluateRadio: 1,
    });
  },
  // 提醒评估
  goEvaluate(e) {
    let time = new Date().getTime();
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    let { rybh,pgname } = e.currentTarget.dataset;
    DDNotify({
      userId: rybh,
      xmbh: this.data.projectDetail.xmbh,
      title: `${this.data.projectDetail.xmfl}:${this.data.projectDetail.xmmc}`,
      content: `${this.data.projectDetail.tname}提醒您及时评估该项目`,
    });addDingLog({
      type: 13,
      tnamea: pgname,
      xmfl: this.data.projectDetail.xmfl,
      tnameb: this.data.Info.jname,
      xmmc: this.data.projectDetail.xmmc,
      tjsj: `${bbTime} ${tjTime}`,
    });
  },
  goApply() {
    let time = new Date().getTime();
    let jtime = time + 24 * 60 * 60 * 1000 * 3;
    let jzdata = new Date(jtime);
    let jzTime = `${jzdata.getFullYear()}-${
      jzdata.getMonth() + 1 < 10
        ? "0" + (jzdata.getMonth() + 1)
        : jzdata.getMonth() + 1
    }-${jzdata.getDate() < 10 ? "0" + jzdata.getDate() : jzdata.getDate()}`;
    //将时间戳格式转换成年月日时分秒
    let date = new Date(time);
    let bbTime = `${date.getFullYear()}-${
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    }-${date.getDate() < 10 ? "0" + date.getDate() : date.getDate()}`;
    let tjTime = `${
      date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    }:${date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()}:${
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    }`;
    applyEvaluation({
      xmbh: this.data.projectDetail.xmbh,
      xmID: this.data.projectDetail.xmID,
      xmpgkssj: `${bbTime} ${tjTime}`,
      sfzg: this.data.evaluateRadio,
    }).then(() => {
      wx.showToast({
        title: "您已申请评估，请耐心等待",
        icon: "none",
      }).then(() => {
        getEvaluationMan(
          this.data.projectDetail.xmfl,
          this.data.projectDetail.xmbh
        )
          .then((res) => {
            res.data.forEach((item) => {
              taskEvaluation({
                xmbh: this.data.projectDetail.xmbh,
                pgname: item.nr,
                rybh: item.nb,
                xmmc: this.data.projectDetail.xmmc,
                xmfl: this.data.projectDetail.xmfl,
                rwjzsj: `${jzTime} ${tjTime}`,
                pgjb: item.na,
                kssj: `${bbTime} ${tjTime}`,
                tname: this.data.projectDetail.tname,
              });
              addDingLog({
                type: 12,
                tnamea: item.nr,
                xmfl: this.data.projectDetail.xmfl,
                tnameb: this.data.Info.jname,
                xmmc: this.data.projectDetail.xmmc,
                tjsj: `${bbTime} ${tjTime}`,
              });
              DDNotify({
                userId: item.nb,
                xmbh: this.data.projectDetail.xmbh,
                title: `${this.data.projectDetail.xmfl}:${this.data.projectDetail.xmmc}`,

                content: `${this.data.projectDetail.tname}已申请该项目的评估,请及时评估`,
              });
            });
          })
          .then(() => {
            wx.showLoading({
              title: "加载中",
            }),
              setTimeout(() => {
                wx.hideLoading();
                this.onLoad({
                  xmbh: this.data.projectDetail.xmbh,
                });
              }, 1000);
          });
      });
    });

    this.closeEvaluste();
    this.onCloseturnover();
  },
  AddEnterprise() {
    this.setData({
      enterpriseIsShow: false,
    });
    wx.navigateTo({
      url: `/pages/programs/intention/intention?zfqID=${this.data.enterpriseDetail.zfqID}&xmbh=${this.data.projectDetail.xmbh}&khbh=${this.data.projectDetail.khbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}&xmfl=${this.data.projectDetail.xmfl}`,
    });
  },
  applyenterprise() {
    if (this.data.contactsEnterpriseData.bs == 0) {
      wx.showToast({
        title: "请选择相关企业",
        icon: "none",
      });
    } else {
      wx.showToast({
        title: "正在关联已流转企业",
        icon: "none",
      });
      contactsEnterprise(this.data.contactsEnterpriseData).then((res) => {
        this.setData({
          enterpriseIsShow: false,
        });
        wx.showToast({
          title: "关联成功，正在前往资料补充页",
          icon: "none",
        });
        this.getDetail();
        setTimeout(() => {
          wx.navigateTo({
            url: `/pages/programs/intention/intention?zfqID=${this.data.enterpriseDetail.zfqID}&xmbh=${this.data.projectDetail.xmbh}&khbh=${this.data.projectDetail.khbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}&xmfl=${this.data.projectDetail.xmfl}`,
          });
        }, 1000);
      });
    }
  },
  onChangeenterprise(e) {
    if (e.detail === "0") {
      this.setData({
        qymc: "",
        enterpriseInputshow: false,
      });
    } else if (e.detail === "1") {
      this.setData({
        enterpriseInputshow: true,
      });
    }
    this.setData({
      sfrzqy: e.detail,
    });
  },
  onchangeInput(e) {
    this.setData({
      qymc: e.detail,
    });
  },
  onCloseenterprise() {
    this.setData({
      enterpriseIsShow: false,
    });
  },
  onClickenterprise(e) {
    let { name, title } = e.currentTarget.dataset;
    if (name === "0") {
      this.setData({
        qymc: "",
        enterpriseInputshow: false,
      });
    } else if (name === "1") {
      this.setData({
        enterpriseInputshow: true,
      });
    }
    this.setData({
      sfrzqy: name,
    });
  },
  goEdit(e) {
    switch (e.target.dataset.name) {
      case "enterprise":
        if (this.data.projectDetail.khbh) {
          wx.navigateTo({
            url: `/pages/programs/intention/intention?zfqID=${this.data.enterpriseDetail.zfqID}&xmbh=${this.data.projectDetail.xmbh}&khbh=${this.data.projectDetail.khbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}&xmfl=${this.data.projectDetail.xmfl}`,
          });
        } else {
          this.setData({
            enterpriseIsShow: true,
          });
        }
        break;
      case "requirement":
        if (this.data.requirement != null) {
          wx.navigateTo({
            url: `/pages/programs/Replenishment/Replenishment?xmbh=${this.data.projectDetail.xmbh}&xqID=${this.data.requirement.xqID}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}`,
          });
        } else {
          wx.navigateTo({
            url: `/pages/programs/Replenishment/Replenishment?xmbh=${this.data.projectDetail.xmbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}`,
          });
        }

        break;
      case "science":
        if (this.data.science != null) {
          wx.navigateTo({
            url: `/pages/programs/science/science?kzID=${this.data.science.kzID}&xmbh=${this.data.projectDetail.xmbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}&xmfl=${this.data.projectDetail.xmfl}`,
          });
        } else {
          wx.navigateTo({
            url: `/pages/programs/science/science?xmbh=${this.data.projectDetail.xmbh}&tname=${this.data.projectDetail.tname}&bm=${this.data.projectDetail.bm}&xmmc=${this.data.projectDetail.xmmc}&xmfl=${this.data.projectDetail.xmfl}`,
          });
        }
        break;
      case "Organization":
        if (e.target.dataset.djbs == 1) {
          wx.navigateTo({
            url: `/pages/programs/Organization/Organization?xmbh=${this.data.projectDetail.xmbh}&djbs=1`,
          });
          this.openDJ();
        } else if (e.target.dataset.djbs == 2) {
          wx.navigateTo({
            url: `/pages/programs/Organization/Organization?xmbh=${e.target.dataset.xmbh}&djbs=2&fwsbh=${e.target.dataset.fwsbh}&fwsname=${e.target.dataset.fwsname}`,
          });
        } else if (e.target.dataset.djbs == 3) {
          wx.navigateTo({
            url: `/pages/programs/Organization/Organization?xmbh=${
              this.data.projectDetail.xmbh
            }&djbs=3&fwsbh=${this.data.projectDetail.fwsbh}&fwsname=${
              this.data.projectDetail.fwsname
            }&ryData=${JSON.stringify(this.data.OrganizationPersen)}`,
          });
          this.setData({
            OrganizationShow: false,
          });
        }
        break;
      default:
        break;
    }
  },
  getRequireINfo() {
    getRequire(this.data.projectDetail.xmbh, this.data.projectDetail.xmfl).then(
      (res) => {
        res.status == 200
          ? this.onLoad({
              xmbh: this.data.projectDetail.xmbh,
            })
          : null;
      }
    );
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      xmbh: options.xmbh,
    });
    wx.showLoading({
      title: "加载中",
    }),
      setTimeout(() => {
        wx.hideLoading();
        this.getDetail();
      }, 1000);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    wx.setStorageSync("xmzbh", 123);
    wx.setStorageSync("xmzname", 123);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log("触发下拉");
    this.getDetail();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
